package model.commands.commandable;

import java.util.List;
import model.Environment;
import model.SyntaxErrorException;
import model.commands.Command;
import model.turtle.Commandable;


/**
 * Name:
 * SETXY x y
 * GOTO x y 
 * 
 * Description:
 * moves turtle to an absolute screen position, where (0, 0) is the center of the screen
 * returns number of pixels moved
 * 
 * @author JLongley
 * @author Erick Gonzalez
 */
public class SetXYCommand extends Command {

    @Override
    public int evaluate(Environment e) throws SyntaxErrorException {
        List<Command> myArguments = getArguments();
        double newX = myArguments.get(0).evaluate(e);
        double newY = myArguments.get(1).evaluate(e);

        Commandable c = e.invokeCommandableMethod(Environment.SET_POSITION, newX, newY);

        double oldX = c.getXCoordinate();
        double oldY = c.getYCoordinate();
        
        int distance = (int) Math.sqrt(Math.pow(newX - oldX, 2) + Math.pow(newY - oldY, 2));
        return distance;
    }

}
